import request from '@/utils/request.js'
import qs from 'qs'

export const employeeLogin = (data) => {
  return request.post('/employee/login', data)
}

export const reqEmployeeInfo = (id) => {
  return request.get(`/employee/${id}`)
}

//修改员工密码
export const reqUpdateEmployeePasswd = (obj) => {
  const formData = new FormData()
  formData.append('oldPwd', obj.oldPwd)
  formData.append('newPwd', obj.newPwd)
  formData.append('rePwd', obj.rePwd)
  // for (const key in obj) {
  //   formData.append(key, obj[key])
  // }
  return request.patch('/employee/updatePwd', formData)
}

//分页查询员工列表
export const reqGetEmpployeePage = (params) => {
  return request.get('/employee/page', { params })
}

// 添加员工
export const reqAddEmployee = (data) => {
  return request.post('/employee', data)
}

// 修改员工(启用、禁用，也是此接口)
export const reqUpdateEmployee = (data) => {
  return request.put('/employee', data)
}

// 启用、禁用员工
export const reqUpdateEmployeeStatus = (emp) => {
  return request.put(`/employee/${emp.id}?status=${emp.status}`)
}

//重置员工登录密码
export const reqResetEmployeePasswd = (ids) => {
  return request.post(
    '/employee/reset',
    qs.stringify({ ids: ids }, { indices: false })
  )
}
//使用get，post得时候我们是使用body下form-data来传输数据得，
// 但是patch默认是以x-www-form-urlencoded的contentType来发送信息，并且信息内容是放在request的body里。

//更新员工信息
export const reqUpdateEmpInfo = (data) => {
  return request.put('/employee', data)
}
